package com.study.services;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.study.model.mdao.IndexMapper;

@Service
@Transactional(rollbackOn = Exception.class)
public class IndexService {

	@Autowired
	IndexMapper indexMapper;
	
	/**
	 * 为主页返回信息
	 * @return 
	 */
	public JSONObject returnIndex() {
		JSONObject obj = new JSONObject();
		//放入图标数据
		int findColleMan = indexMapper.findColleMan(1712);//查询集客
		int findCustomer = indexMapper.findCustomer();//客户
		int findOrder = indexMapper.findOrder();//订单
		int findComplan = indexMapper.findComplan();//投诉
		obj.put("colle", findColleMan);
		obj.put("custo", findCustomer);
		obj.put("order", findOrder);
		obj.put("compl", findComplan);
		//放入四个率
		float findColleAll = indexMapper.findColleAll();
		if (findColleAll!=0&&findColleMan!=0) {
			float a=((float)findColleMan/findColleAll)*100;
			obj.put("yescolle", (float)(Math.round(a*10)/10));//成功集客了几人
		}
		float noman = indexMapper.findColleMan(1711);//查询集客失败记录
		if (findColleAll!=0&&noman!=0) {
			float a=(noman/findColleAll)*100;
			obj.put("nocolle", (float)(Math.round(a*10)/10));//成功集客了几人
		}
		float findOrderAll = indexMapper.findOrderAll();
		if (findOrderAll!=0&&findOrder!=0) {
			float a= ((float)findOrder/findOrderAll)*100;
			obj.put("yesorder", (float)(Math.round(a*10)/10));//成功订单几笔
		}
		
		float findBuy = indexMapper.findBuy();//卖出的商品量
		float findReturnBuy = indexMapper.findReturnBuy();//被退货的商品量
		System.out.println(findBuy+"  "+findReturnBuy);
		if (findBuy!=0&&findReturnBuy!=0) {
			//(float)(Math.round(totalPrice*100)/100);
			float a=(findReturnBuy/findBuy)*100;
			obj.put("returnlv", (float)(Math.round(a*10)/10));//退货率
		}
		System.out.println(obj);
		//查询五条投诉信息
		obj.put("tousu", indexMapper.findWuItem());//五条投诉信息
		
		//集客信息
		obj.put("jike", indexMapper.findFormItem());//五条集客信息

		//员工信息
		obj.put("users", indexMapper.findManItems());//员工信息
		return obj;
	}
	
}
